package server;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

public class Response {

    private OutputStream outputStream;

    public Response() {
    }

    public Response(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    public void outPut(String content) throws IOException {
        outputStream.write((content.getBytes()));
    }
    /**
     *
     * @param path url 获取绝对路径读取静态资源输出
     */
    public void ouputHtml(String webappsPath,String path) throws IOException {

        String absoluteResourcePath = webappsPath + path;

        System.out.println("absoluteResourcePath: " + absoluteResourcePath);
        File file = new File(absoluteResourcePath);
        if(file.exists() && file.isFile()){
            StaticResourceUtil.outputStaticResource(new FileInputStream((file)), outputStream);
        }else{
            outPut(HttpProtocolUtil.getHttpHeader404());
        }
    }
}
